package com.bi.autotest.pages;

import com.auto.base.PageAppium;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

/**
 * Created by yidian on 2018/3/27.
 */
public class MyLoginPage extends PageAppium {

    public final String IS_LOGIN_PAGE_TEXT="《宜店用户服务协议》";
    public final String NAME_AREA_XP="android.widget.EditText";
    public final String PASSWORD_AREA_TEXT="输入验证码";
    public final String LOGIN_BUTTON_TEXT="确定";
    public final String AGREE_XP="//android.view.View[@content-desc=' 我已阅读并同意']";
    public final String TO_LOGIN_BUTTON_XP="//android.view.View[@content-desc='登录并收款']";
    public final String CONFIRM_LOGIN_ID="确认登录";

    public final String ISCACHE_SUCCESSPAGE="设置金额";
    public final String GG_BUTTON_SELECT_XP="//android.view.View[@content-desc='故宫']";

    public MyLoginPage(AndroidDriver androidDriver) {
        super(androidDriver);
    }


    /**
     * 获取登录并收款的按钮
     * @return
     */
    public AndroidElement getToLoginButton(){
        return waitAutoByXp(TO_LOGIN_BUTTON_XP);
    }

    /**
     *判断是否是登录界面
     * @return
     */
    public boolean isLoginPage(){
        return isNameElementExist(IS_LOGIN_PAGE_TEXT,5);
    }

    /**
     *获取登陆的按钮
     * @return
     */
    public AndroidElement getLoginButton(){
        return waitAutoByName(LOGIN_BUTTON_TEXT);
    }

    /**
     *获取选择门店时登陆的按钮
     * @return
     */
    public AndroidElement getConfirmLoginButton(){
        return waitAutoByName(CONFIRM_LOGIN_ID);
    }

    /**
     * 获取输入手机号的输入框
     */
    public AndroidElement getNameInputArea(){
        return getManyElementByClassName(NAME_AREA_XP,2).get(0);
    }

    /**
     * 获取输入验证码的输入框
     */
    public AndroidElement getPassWordInputArea(){
        return getManyElementByClassName(NAME_AREA_XP,2).get(1);
    }

    /**
     * 获取选择门店时故宫的按钮
     */
    public AndroidElement getGGButton(){
        return waitAutoByXp(GG_BUTTON_SELECT_XP);
    }


    /**
     * 获取阅读并同意的文字  用来选择同意的对勾
     */
    public AndroidElement getAgreeArea(){
        return waitAutoByXp(AGREE_XP);
    }

    /**
     * 是否登陆成功的验证  设置为等待5s时间查找控件
     */
    public boolean isLoginSuccess(){
        return isNameElementExist(CONFIRM_LOGIN_ID,5);
    }

    /**
     * 判断是不是有缓存直接登陆成功的页面
     */
    public boolean isCacheLoginSuccessPage(){
        return isNameElementExist(ISCACHE_SUCCESSPAGE,5);
    }



}
